package com.ztesoft.sca.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.ztesoft.sca.model.QcSceneModel;

@Component
public class QcSceneDaoImpl implements QcSceneDao {
    private JdbcTemplate jdbcTemplate;

    @Autowired
    public QcSceneDaoImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
	
	@Override
	public List<QcSceneModel> selectListQcScene(long id, int from, int size) {
        String sqlStr="SELECT * FROM (SELECT ROWNUM rn,scene_id, scene_name,scene_desc,create_time,status "
        		+ "FROM (SELECT scene_id,scene_name,scene_desc,create_time,status FROM SCA_SCENE)WHERE ROWNUM<=? ORDER BY scene_id desc) t2 WHERE t2.rn >=?";
        StringBuffer sqlBuf =new StringBuffer(sqlStr);
        if (from < 0) {
            from = Integer.MAX_VALUE; 
        }
        Object[] param = new Object[]{size,from};
        List<QcSceneModel> list = this.jdbcTemplate.query(sqlBuf.toString(),param,BeanPropertyRowMapper.newInstance(QcSceneModel.class));
        return list;
	}

	@Override
	public void insertQcScene(QcSceneModel aiChat) {
        StringBuffer sqlBuf = new StringBuffer("insert into SCA_SCENE " +
                "" +
                "  (scene_id,scene_name,scene_desc,create_time,status)" +
                "" +
                "VALUES" +
                "" +
                "  (?, ?,?, ?,?)");
        Object[] param = new Object[]{aiChat.getSceneId(),aiChat.getSceneName(),aiChat.getSceneDesc(),aiChat.getCreateTime(),aiChat.getStatus()};
        this.jdbcTemplate.update(sqlBuf.toString(),param);
	}

}
